﻿
Imports System.Runtime.CompilerServices
Imports osi.root.delegates
Imports osi.root.utils

Public Module _event_comb_success_behavior
    <Extension()> Public Function success_behavior(ByVal ec As event_comb,
                                                   ByVal suc As _do(Of Boolean),
                                                   ByVal fal As void) As Boolean
        If Not ec Is Nothing AndAlso ec.success_finished() AndAlso do_(suc, False) Then
            Return True
        Else
            void_(fal)
            Return False
        End If
    End Function

    <Extension()> Public Function success_behavior(ByVal ec As event_comb,
                                                   ByVal d As _do(Of Boolean)) As Boolean
        Return success_behavior(ec, d, Nothing)
    End Function

    <Extension()> Public Function success_behavior(ByVal ec As event_comb,
                                                   ByVal suc As void,
                                                   ByVal fal As void) As Boolean
        Return success_behavior(ec,
                                Function() As Boolean
                                    void_(suc)
                                    Return True
                                End Function,
                                fal)
    End Function

    <Extension()> Public Function success_behavior(ByVal ec As event_comb, ByVal d As void) As Boolean
        Return success_behavior(ec, Function() As Boolean
                                        void_(d)
                                        Return True
                                    End Function)
    End Function
End Module
